/**
 * urk相关
 * @date: 2019-12-25

 */
import qs from 'query-string';
export function isUrl(path) {
  /* eslint no-useless-escape:0 */
  var reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)(:[\d]+)?((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g;
  return reg.test(path);
}
/**
 * 生成带Get参数的URL
 * @param {String} url      原来的url
 * @param {Object} params   get 参数
 */

export function generateUrlWithGetParam(url, params) {
  var newUrl = url;

  if (params && Object.keys(params).length >= 1) {
    var newParams = params; // filterNullValueObject

    if (Object.keys(newParams).length >= 1) {
      newUrl += "".concat(url.indexOf('?') >= 0 ? '&' : '?').concat(qs.stringify(newParams));
    }
  }

  return newUrl;
}
/**
 * 得到get请求后面的参数部分,并去掉参数值为空的
 * @param param
 * @returns {String}
 */

export function getUrlParam(param) {
  var on = true;
  var result = '';

  for (var item in param) {
    if (on) {
      on = false;

      if (param[item] || param[item] === 0 || param[item] === false) {
        result = "?".concat(item, "=").concat(param[item]);
      } else {
        result = '?';
      }
    } else if (param[item] || param[item] === 0 || param[item] === false) {
      result = "".concat(result, "&").concat(item, "=").concat(param[item]);
    }
  }

  return result;
}